import type { ComponentResolver } from 'unplugin-vue-components/types'

/**
 * Ep Designer Core Resolver
 * @returns ComponentResolver
 * @description 解析器，用于解析组件库中的组件
 */
export function EpDesignerCoreResolver(): ComponentResolver {
  return {
    type: 'component',
    resolve: (name: string) => {
      // 处理 PC 端组件
      if (/^Ep[A-Z]/.test(name)) {
        const kebabName = name.replace(/([Ep])([A-Z])/g, '$1-$2').toLowerCase()
        return {
          name,
          from: `ep-designer-core/es/components/${kebabName}`,
          sideEffects: `ep-designer-core/es/components/${kebabName}/style.css`
        }
      }

      // 处理移动端组件
      if (/^M[A-Z]/.test(name)) {
        const kebabName = name.replace(/([M])([A-Z])/g, '$1-$2').toLowerCase()
        return {
          name,
          from: `ep-designer-core/es/mobile-components/${kebabName}`,
          sideEffects: `ep-designer-core/es/mobile-components/${kebabName}/style.css`
        }
      }
    }
  }
}
